/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#include "../import/head.h"
#include "../impl/head.h"
#include "lock_free_queue_impl.h"

/////////////////////////////////////////////////////////////////////////////////////////
// 
namespace xos_box
{
    ////////////////////////////////////////////////////////////////////////////////////
    // 

    static lock_free_queue_impl::ITEM_DATA xos_item_data;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // lock_free_queue_impl

    lock_free_queue_impl::lock_free_queue_impl()
    {
    }

    lock_free_queue_impl::~lock_free_queue_impl()
    {
        term();
    }

    ////////////////////////////////////////////////////////////////////////////////////
    // 

    int lock_free_queue_impl::get_xos_item_data( ITEM_DATA *& item_ptr )
    {
        int ret = 0;
        xos_item_data.set_container( mgr::container() );
        item_ptr = &xos_item_data;
        return ret;
    }

    int lock_free_queue_impl::static_user_init()
    {
        int ret = 0;
        return ret;
    }

    int lock_free_queue_impl::static_user_term()
    {
        int ret = 0;
        return ret;
    }

    int lock_free_queue_impl::init()
    {
        int ret = 0;
        m_queue.init( mgr::container() );
        return ret;
    }

    int lock_free_queue_impl::term()
    {
        int ret = 0;
        m_queue.term();
        return ret;
    }

    ////////////////////////////////////////////////////////////////////////////////////
    // 

    // 
    // add back
    // 
    int lock_free_queue_impl::push_back( xos::i_release * pObj )
    {
        int ret = 0;
        m_queue.push_back( pObj );
        return ret;
    }

    // 
    // pop front
    // 
    xos::i_release * lock_free_queue_impl::pop_front()
    {
        xos::i_release * pRet = 0;
        pRet = m_queue.pop_front();
        return pRet;
    }

    // 
    // release all
    // 
    int lock_free_queue_impl::release_all()
    {
        int ret = 0;
        m_queue.release_all();
        return ret;
    }
} // xos
